package com.ds.console.service;

import com.ds.common.Page;
import com.ds.common.PageInfo;
import com.ds.common.util.BeanUtil;
import com.ds.console.bo.SysUserBo;
import com.ds.console.entity.SysUser;
import com.ds.console.mapper.SysUserMapper;
import com.ds.console.vo.SysUserVo;
import com.github.pagehelper.PageHelper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.io.Serializable;


@Slf4j
@Service
@RequiredArgsConstructor
public class SysUserService {

    private final SysUserMapper sysUserMapper;

    public boolean insert(SysUserBo param) {
        SysUser entity = BeanUtil.copyProperties(param, SysUser.class);
        int count = sysUserMapper.insert(entity);
        return count > 0;
    }

    public boolean update(SysUserBo param) {
        SysUser entity = BeanUtil.copyProperties(param, SysUser.class);
        int count = sysUserMapper.updateById(entity);
        return count > 0;
    }

    public boolean delete(Serializable id) {
        int count = sysUserMapper.deleteById(id);
        return count > 0;
    }

    public SysUserVo select(Serializable id) {
        SysUser entity = sysUserMapper.selectById(id);
        return BeanUtil.copyProperties(entity, SysUserVo.class);
    }

    public PageInfo<SysUserVo> selectPage(Page<SysUserBo> param) {
        PageHelper.startPage(param.getPageNum(), param.getPageSize());
        return PageInfo.build(sysUserMapper.selects(param.getParam()));
    }

}